package com.hr.jobTimeRecord.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hr.common.annotation.Log;
import com.hr.common.core.controller.BaseController;
import com.hr.common.core.domain.AjaxResult;
import com.hr.common.enums.BusinessType;
import com.hr.jobTimeRecord.domain.JobTimeRecord;
import com.hr.jobTimeRecord.service.IJobTimeRecordService;
import com.hr.common.utils.poi.ExcelUtil;
import com.hr.common.core.page.TableDataInfo;

/**
 * 员工入职时间记录Controller
 * 
 * @author guan
 * @date 2024-07-16
 */
@RestController
@RequestMapping("/manage/record")
public class JobTimeRecordController extends BaseController
{
    @Autowired
    private IJobTimeRecordService jobTimeRecordService;

    /**
     * 查询员工入职时间记录列表
     */
    @PreAuthorize("@ss.hasPermi('manage:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(JobTimeRecord jobTimeRecord)
    {
        startPage();
        List<JobTimeRecord> list = jobTimeRecordService.selectJobTimeRecordList(jobTimeRecord);
        return getDataTable(list);
    }

    /**
     * 导出员工入职时间记录列表
     */
    @PreAuthorize("@ss.hasPermi('manage:record:export')")
    @Log(title = "员工入职时间记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JobTimeRecord jobTimeRecord)
    {
        List<JobTimeRecord> list = jobTimeRecordService.selectJobTimeRecordList(jobTimeRecord);
        ExcelUtil<JobTimeRecord> util = new ExcelUtil<JobTimeRecord>(JobTimeRecord.class);
        util.exportExcel(response, list, "员工入职时间记录数据");
    }

    /**
     * 获取员工入职时间记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:record:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(jobTimeRecordService.selectJobTimeRecordByUserId(userId));
    }

    /**
     * 新增员工入职时间记录
     */
    @PreAuthorize("@ss.hasPermi('manage:record:add')")
    @Log(title = "员工入职时间记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JobTimeRecord jobTimeRecord)
    {
        return toAjax(jobTimeRecordService.insertJobTimeRecord(jobTimeRecord));
    }

    /**
     * 修改员工入职时间记录
     */
    @PreAuthorize("@ss.hasPermi('manage:record:edit')")
    @Log(title = "员工入职时间记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JobTimeRecord jobTimeRecord)
    {
        return toAjax(jobTimeRecordService.updateJobTimeRecord(jobTimeRecord));
    }

    /**
     * 删除员工入职时间记录
     */
    @PreAuthorize("@ss.hasPermi('manage:record:remove')")
    @Log(title = "员工入职时间记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(jobTimeRecordService.deleteJobTimeRecordByUserIds(userIds));
    }

    /**
     * 查询员工入/离职情况
     */
//    @PreAuthorize("@ss.hasPermi('manage:record:count')")
    @GetMapping("/count")
    public JobTimeRecord count(JobTimeRecord jobTimeRecord)
    {
        return jobTimeRecordService.selectJobTimeRecordCount(jobTimeRecord);
    }

    /**
     * 查询员工入/离职情况(def)
     */
//    @PreAuthorize("@ss.hasPermi('manage:record:count')")
    @GetMapping("/countDef")
    public JobTimeRecord countDef(JobTimeRecord jobTimeRecord)
    {
        return jobTimeRecordService.selectJobTimeRecordCountDef(jobTimeRecord);
    }
}
